home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SOUND.SWG / 0009_SBVOICE.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  10KB  |  339 lines

  1. {---------------------------------------------------------------------------
  2.                    Unit SBVoice (v1.10) For Turbo Pascal 6.0
  3.        For interfacing With the SoundBlaster's digitized voice channel.
  4.            Copyright (c) 1991, Amit K. Mathur, Windsor, Ontario.
  5.  
  6.                         By: Amit K. Mathur
  7.                             3215 St. Patrick's Drive
  8.                             Windsor, Ontario
  9.                             N9E 3H2 CANADA
  10.                         Ph: (519) 966-6924
  11.  
  12.  Networks:  RIME(tm) R/O ->WinDSor, ILink (Shareware), NA-Net (Gaming),
  13.             WWIVNet (#198@5950), or direct on NorthSTAR (519)735-1504.
  14.  
  15.  These routines are released to the public domain.  However I will gladly
  16.  accept contributions towards further development of this and other products.
  17.  Please send any changes or improvements my way.  and I'm interested in
  18.  other SoundBlaster utilities and Programming tools.  Thanks in advance.
  19.  --------------------------------------------------------------------------}
  20.  
  21. {$O+,F+}
  22. { Allow this Unit to Be Overlayed (doesn't affect Compilation if you decide
  23.   not to overlay it), and Force Far calls.                                 }
  24.  
  25. Unit SBVoice;
  26.  
  27. Interface
  28.  
  29. Uses MemAlloc;                                    { Memory Allocation Proc }
  30.  
  31. Var
  32. {$ifNDEF NoSBVoiceArray}                          { to use your own        }
  33.      SoundFile: Array[1..64000] of Byte;          { whatever size you want }
  34. {$endif}
  35.      sgSBDriver, ofSBDriver: Word;                { seg and ofs of Driver  }
  36.      SBDriver: Pointer;                           { Pointer to the driver  }
  37.      StatusWord: Word;                            { stores SB status       }
  38.      SBFound: Boolean;                            { whether Init worked    }
  39.  
  40. Procedure loaddriver(fi:String);
  41. { Loads CT-VOICE.DRV into memory.  'fi' is the path to the driver.         }
  42.  
  43. Procedure closedriver;
  44. { Clean up routine.  not Really necessary if your Program is over.         }
  45.  
  46. Procedure loadvoice(f:String;start,size:Word);
  47. { Load 'f' into memory.  Start is the start of the area within
  48.   'f' to load and size is the amount to laod.  if you set size to 0
  49.   then it will load the entire File.                                      }
  50.  
  51. Function sb_getversion:Integer;
  52. { Get the version number of the CT-VOICE.DRV
  53.   Returns the Version number                                              }
  54.  
  55. Function sb_init:Integer;
  56. { Initialize the SoundBlaster.  Call this right after load driver, unless
  57.   you have to change the BaseIOAddress or Interrupt number and haven't
  58.   changed the CT-VOICE.DRV File itself.
  59.   Returns:  0 - no problem
  60.             1 - Sound card failiure
  61.             2 - I/O failiure
  62.             3 - DMA interrupt failiure                                    }
  63.  
  64. Procedure sb_output(sg,os:Word);
  65. { Output the digitized Sound.  You must load the Sound first!
  66.   sg and os are the segment and offset of either SoundFile or whatever
  67.   Array you use to store the Sound.  if you use a .VOC File then call
  68.   With 26 added to the offset.                                            }
  69.  
  70. Procedure sb_setstatusWord(sg,os:Word);
  71. { Sets the location of the status Word.  This is the third thing you should
  72.   do, after loading the driver and initializing it.
  73.   The StatusWord will contain $0FFFF if input/output is in output, and
  74.   0 when it's done.  It will also hold the values of the markers in voice
  75.   Files if any are encounterred, allowing you to coordinate output with
  76.   your Programs.                                                          }
  77.  
  78. Procedure sb_speaker(mode:Word);
  79. { Set the speaker on/off.  off is mode 0, and On is anything else.  This
  80.   is the fourth thing you should do in your initialization.               }
  81.  
  82. Procedure sb_uninstall;
  83. { Uninstall the driver from memory.   Used by CloseDriver.                }
  84.  
  85. Procedure sb_setIOaddress(add:Word);
  86. { Override the IOaddress found inside the CT-VOICE.DRV File.  Add is the
  87.   new IO address.                                                         }
  88.  
  89. Procedure sb_setinterruptnumber(intno:Word);
  90. { Allows you to override the Interrupt number in the driver.  IntNo is your
  91.   new interrupt number (3, 5, 7 or 9).                                    }
  92.  
  93. Procedure sb_stopoutput;
  94. { Stops the output in progress                                            }
  95.  
  96. Function sb_pauseoutput: Integer;
  97. { PaUses the output in progress.
  98.   Returns:  0 - success
  99.             1 - fail                                                      }
  100.  
  101. Function sb_continueoutput: Integer;
  102. { Continues a paused output.
  103.   Returns:  0 - success
  104.             1 - fail (nothing to continue)                                }
  105.  
  106. Function sb_breakloop(mode:Word): Integer;
  107. { Breaks out of the currect output loop.
  108.   Modes:  0 - continue round, stop when done
  109.           1 - stop immediately
  110.   Returns:  0 - success
  111.             1 - not in loop                                               }
  112.  
  113. Procedure sb_input(highlength,lowlength,seginputbuff,ofsinputbuff:Word);
  114. { Input digitized Sound.
  115.   HighLength: The high Byte of the length of the input buffer.
  116.   LowLength:  The low Byte of the length of the input buffer.
  117.   SegInputBuff: The Segment of the start of the input buffer.
  118.   ofsInputBuff: The offset of the start of the input buffer.              }
  119.  
  120. Procedure sb_setuserFunction(segaddress,ofsaddress:Word);
  121. { Sets up a user Function that the SB calls when it encounters a new data
  122.   block.  It must perForm a Far ret, preserve DS,DI,SI and flag register.
  123.   Clear Carry flag if you want the driver to process the block, or set it
  124.   if your routine will.  It must be clear if the block Type is 0, that
  125.   is the terminate block.
  126.   SegAddress is the segment of your user Function in memory.
  127.   ofsAddress is the ofset of your user Function in memory.                }
  128.  
  129. Implementation
  130.  
  131. Uses Dos;
  132.  
  133. Procedure Abort(s:String);
  134. begin
  135.   Writeln('The Following Error Has Occurred: ',s);
  136.   Writeln('Remedy and try again.  We apologize For any inconvenience.');
  137.   halt(1);
  138. end;
  139.  
  140. Procedure loaddriver(fi:String);
  141. Var f: File;
  142.     k: Integer;
  143.     t: String[8];
  144. begin
  145.     assign(f,fi+'CT-VOICE.DRV');
  146.     {$I-} Reset(f,1); {$I+}
  147.     if Ioresult <> 0 then
  148.         Abort('Cannot Open '+fi+'CT-VOICE.DRV');
  149.     blockread(f,Mem[sgSBDriver:ofSBDriver],Filesize(f));
  150.     close(f);
  151.     t:='';
  152.     For k:=0 to 7 do
  153.         t:=t+chr(Mem[sgSBDriver:ofSBDriver+k+3]);
  154.     if t<>'CT-VOICE' then
  155.         abort('Invalid CT-VOICE Driver!');
  156. end;
  157.  
  158. Procedure closedriver;
  159. begin
  160.     sb_uninstall;
  161.     if dalloc(sbdriver)=0 then
  162.         abort('Uninstall Error!');
  163. end;
  164.  
  165. Procedure loadvoice(f:String;start,size:Word);
  166. Var fi: File;
  167.     k: Word;
  168. begin
  169.     assign(fi,f);
  170.     {$I-} Reset(fi,1); {$I+}
  171.     if Ioresult <> 0 then
  172.        abort('Cannot Open '+f+'!');
  173.     k:=0;
  174.     seek(fi,start);
  175.     if size=0 then size:=Filesize(fi);
  176.     blockread(fi,Mem[seg(SoundFile):ofs(SoundFile)],size);
  177.     close(fi);
  178. end;
  179.  
  180. Function sb_getversion: Integer; Assembler;
  181. Asm
  182.    push  bp
  183.    mov   bx,0
  184.    call  SBDriver
  185.    pop   bp
  186. end;
  187.  
  188. Procedure sb_setIOaddress(add:Word); Assembler;
  189. Asm
  190.    push  bp
  191.    mov   bx,1
  192.    mov   ax,add
  193.    call  SBDriver
  194.    pop   bp
  195. end;
  196.  
  197. Procedure sb_setinterruptnumber(intno:Word); Assembler;
  198. Asm
  199.    push  bp
  200.    mov   bx,2
  201.    mov   ax,intno
  202.    call  SBDriver
  203.    pop   bp
  204. end;
  205.  
  206. Procedure sb_stopoutput; Assembler;
  207. Asm
  208.    push  bp
  209.    mov   bx,8
  210.    call  SBDriver
  211.    pop   bp
  212. end;
  213.  
  214. Function sb_init: Integer; Assembler;
  215. Asm
  216.    push  bp
  217.    mov   bx, 3
  218.    call  SBDriver
  219.    pop   bp
  220. end;
  221.  
  222. Function sb_pauseoutput: Integer; Assembler;
  223. Asm
  224.    push  bp
  225.    mov   bx,10
  226.    call  SBDriver
  227.    pop   bp
  228. end;
  229.  
  230. Function sb_continueoutput: Integer; Assembler;
  231. Asm
  232.    push  bp
  233.    mov   bx,11
  234.    call  SBDriver
  235.    pop   bp
  236. end;
  237.  
  238. Function sb_breakloop(mode:Word): Integer; Assembler;
  239. Asm
  240.    push  bp
  241.    mov   bx,12
  242.    mov   ax,mode
  243.    call  SBDriver
  244.    pop   bp
  245. end;
  246.  
  247. Procedure sb_output(sg,os:Word); Assembler;
  248. Asm
  249.     push bp
  250.     push di
  251.     mov  bx,6
  252.     mov  di,os             { offset of voice  }
  253.     mov  es,sg             { segment of voice }
  254.     call SBDriver
  255.     pop  di
  256.     pop  bp
  257. end;
  258.  
  259. Procedure sb_input(highlength,lowlength,seginputbuff,ofsinputbuff:Word);
  260. Assembler;
  261. Asm
  262.     push bp
  263.     push di
  264.     mov  bx,7
  265.     mov  dx,highlength
  266.     mov  cx,lowlength
  267.     mov  es,seginputbuff
  268.     mov  di,ofsinputbuff
  269.     call SBDriver
  270.     pop  di
  271.     pop  bp
  272. end;
  273.  
  274. Procedure sb_setstatusWord(sg,os:Word); Assembler;
  275. Asm
  276.     push bp
  277.     push di
  278.     mov  bx,5
  279.     mov  di,os
  280.     mov  es,sg
  281.     call SBDriver
  282.     pop  di
  283.     pop  bp
  284. end;
  285.  
  286. Procedure sb_speaker(mode:Word); Assembler;
  287. Asm
  288.    push  bp
  289.    mov   bx,4
  290.    mov   ax,mode
  291.    call  SBDriver
  292.    pop   bp
  293. end;
  294.  
  295. Procedure sb_uninstall; Assembler;
  296. Asm
  297.    push  bp
  298.    mov   bx,9
  299.    call  SBDriver
  300.    pop   bp
  301. end;
  302.  
  303. Procedure sb_setuserFunction(segaddress,ofsaddress:Word); Assembler;
  304. Asm
  305.    push  bp
  306.    mov   dx,segaddress
  307.    mov   ax,ofsaddress
  308.    mov   bx,13
  309.    call  SBDriver
  310.    pop   bp
  311. end;
  312.  
  313.  
  314. begin {set up SB}
  315.  
  316.   if DosMemAvail < 5000 then                           { lower the heap   }
  317.       abort('not Enough Memory');                      { With $M to fix   }
  318.   StatusWord:=MAlloc(SBDriver,5000);
  319.   if StatusWord<>0 then
  320.       abort('Memory Allocation Error');
  321.  
  322.   sgSBDriver:=MemW[seg(SBDriver):ofs(SBDriver)+2];
  323.   ofSBDriver:=MemW[seg(SBDriver):ofs(SBDriver)];
  324.  
  325.   Loaddriver('');                                      { change at will   }
  326.   if sb_init<>0 then                                   { or stick in your }
  327.       SBFound:=False                                   { own Program init }
  328.   else
  329.       SBFound:=True;
  330.  
  331.   if SBFound then begin
  332.       sb_setstatusWord(seg(statusWord),ofs(statusWord));
  333.       sb_speaker(1);                                   { turn SB on       }
  334.   end;
  335. end.
  336.  
  337.  
  338. {There's the Unit For .VOC playing.}
  339.